package org.sjs.dreamfly.biz.movie

import android.net.Uri
import org.json.JSONObject
import org.sjs.dreamfly.browser.WebLocation
import org.sjs.dreamfly.model.MovieInfo

object MovieUtil {
    private val XIGUA_MOVIE_ALL_API_PATH = "https://www.ixigua.com/na/monorepo/bff/api/lvideo_filter/get_category_lvideos?"
    fun isLoadMoreApi(url: String): Boolean {
        return url.startsWith(XIGUA_MOVIE_ALL_API_PATH)
    }

    fun isIXiGuaFilterResponse(params: String): Boolean {
        return params.contains("www.ixigua.com")
    }

    fun getMovieId(movieInfo: MovieInfo): String {
        movieInfo.refer?.let {
            if (isXiGuaMovie(movieInfo)) {
                return Uri.parse(it).pathSegments.last()
            } else {
                return it.split('/').last().split('.').first()
            }
        }
        return System.currentTimeMillis().toString()
    }

    fun isXiGuaMovie(movieInfo: MovieInfo): Boolean {
        return movieInfo.refer?.contains(".ixigua.com") == true
    }

    fun isSingletonMovie(channel: String?): Boolean? {
        return when (channel) {
            MovieConstants.CHANNEL_TYPE_DIANYING -> true
            MovieConstants.CHANNEL_TYPE_DIANSHIJU -> false
            MovieConstants.CHANNEL_TYPE_JILUPIAN -> true
            MovieConstants.CHANNEL_TYPE_SHAOER -> false
            MovieConstants.CHANNEL_TYPE_DONGMAN -> false
            MovieConstants.CHANNEL_TYPE_ZONGYI -> true
            else -> null
        }
    }
}